from time import sleep
# def Notify(operation):
#     def wrapper(x):
#         print("开始转换....")
#         res=operation(x)
#         print("结束转换....")
#         return f"膨胀10倍{res * 10}"
#     return wrapper


def Notify(operation):
    def wrapper(*x, **kwargs):
        print("开始转换....")
        res = operation(*x, **kwargs)
        print("结束转换....")
        return f"膨胀10倍{res * 10}"

    return wrapper


def Notify1(text):
    def decorator(operation):
        def wrapper(*x, **kwargs):
            print(text)
            print("开始转换....")
            res = operation(*x, **kwargs)
            print("结束转换....")
            return f"膨胀10倍{res * 10}"

        return wrapper

    return decorator


def amplify(rate):
    def decorator(operation):
        def wrapper(*x, **kwargs):
            res = operation(*x, **kwargs)
            return res * rate

        return wrapper

    return decorator


# @Notify1("====美元转换人民币====")
def usd_to_cny(amount):
    cny = amount / 0.14
    print(f"{amount}美元转换成人民币为：{cny:.1f}人民币")
    return cny


# some practical usage for decorators


def timer(func):
    import time

    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"Function took {end_time - start_time:.4f} seconds")
        return result

    return wrapper


def my_sleep(seconds):
    def decorator(func):
        def wrapper(*args, **kwargs):
            print(f"Sleeping for {seconds} seconds before calling {func.__name__}")
            sleep(seconds)
            return func(*args, **kwargs)

        return wrapper

    return decorator


@amplify(10000)
@timer
@my_sleep(2)
def usd_to_cny_with_time(amount, time, name="匿名", location="未知"):
    cny = amount / 0.14
    print(f"{name}在{time},{location}, {amount}美元转换成人民币为：{cny:.1f}人民币")
    return cny


# cny=usd_to_cny(500)
cny = usd_to_cny_with_time(500, "2024年6月", name="小王", location="银行")
print(cny)
